﻿@Html.DevExpress().GridView(
            settings =>
            {
                settings.Name = "gvDocument";
                settings.KeyFieldName = "FDocId";
                settings.CallbackRouteValues = new { Controller = "DocumentPub", Action = "DocumentListPartial" };
                settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

                settings.Columns.Add(column =>
                {
                    column.Caption = "操作";

                    column.SetDataItemTemplateContent(c =>
                    {
                        Html.DevExpress().HyperLink(s =>
                        {
                            s.Name = "linkEdit" + c.VisibleIndex; s.Properties.Text = "修改";
                            s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_Edit.png"); s.ToolTip = s.Properties.Text; s.Properties.ClientSideEvents.Click = "function(){DocumentEdit('" + DataBinder.Eval(c.DataItem, "FDocId") + "')}"; s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
                        }).GetHtml();
                        ViewContext.Writer.Write("&nbsp;&nbsp;");
                        Html.DevExpress().HyperLink(s =>
                        {
                            s.Name = "linkDel" + c.VisibleIndex; s.Properties.Text = "删除";
                            s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_delete.png"); s.ToolTip = s.Properties.Text; s.Properties.ClientSideEvents.Click = "function(){documentDel('" + DataBinder.Eval(c.DataItem, "FDocId") + "')}"; s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
                            if (DataBinder.Eval(c.DataItem, "FIsNeedAudit").ToString() == "Y")
                            {
                                if (DataBinder.Eval(c.DataItem, "FStatus").ToString() == "Y")
                                {
                                    if (DataBinder.Eval(c.DataItem, "FIsEnroll").ToString() != "U")//非修改状态
                                    {
                                        s.ClientVisible = false;
                                    }
                                }
                            }

                        }).GetHtml();

                    });
                    column.Settings.AllowDragDrop = DefaultBoolean.False;
                    column.Settings.AllowSort = DefaultBoolean.False;
                    column.CellStyle.Wrap = DefaultBoolean.False;
                });

                settings.Columns.Add(column =>
                {
                    column.Caption = "类别";
                    column.FieldName = "FDocClsName";
                    
                    column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                    column.CellStyle.Wrap = DefaultBoolean.False;
                });
                  
                        settings.Columns.Add(column =>
                        {
                            column.Caption = "标题";
                            //column.FieldName = "FTitle";
                            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
                            column.Width = 300;
                            
                            column.CellStyle.Wrap = DefaultBoolean.False;

                            column.SetDataItemTemplateContent(c =>
                            {
                                string title = DataBinder.Eval(c.DataItem, "FTitle").ToString();
                                string substringTitle ="";
                                if (title.Length > 25)
                                {
                                    substringTitle = title.Substring(0, 25) + "...";
                                }
                                else
                                {
                                    substringTitle = title;
                                }
                                ViewContext.Writer.Write(substringTitle);
                            });
               });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = "发布部门/工作组";
                            column.FieldName = "FDeptName";



                            column.CellStyle.Wrap = DefaultBoolean.False;
                        });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = "发布人";
                            column.FieldName = "FEmpName";

                            column.CellStyle.Wrap = DefaultBoolean.False;
                        });

                        settings.Columns.Add(column =>
                        {
                            column.Caption = "发布日期";

                            column.SetDataItemTemplateContent(c =>
                            {

                                DateTime dt = DateTime.Parse(DataBinder.Eval(c.DataItem, "FPubDate").ToString());
                                ViewContext.Writer.Write(dt.ToString("yyyy-MM-dd"));
                            });
                            column.CellStyle.Wrap = DefaultBoolean.False;
                        });

                        settings.Columns.Add(column =>
                        {
                            column.Caption = "置顶";

                            column.SetDataItemTemplateContent(c =>
                            {

                                if (DataBinder.Eval(c.DataItem, "FIsTop").ToString() == "1")
                                {
                                    ViewContext.Writer.Write("√");
                                }
                                else
                                {
                                    ViewContext.Writer.Write("&nbsp;");
                                }

                            });
                            column.CellStyle.Wrap = DefaultBoolean.False;
                        });
                        settings.Columns.Add(column =>
                        {
                            column.Caption = "状态";

                            column.SetDataItemTemplateContent(c =>
                            {

                                if (DataBinder.Eval(c.DataItem, "FStatus").ToString() == "N")
                                {
                                    ViewContext.Writer.Write("审核中");
                                }
                                else
                                {
                                    switch (DataBinder.Eval(c.DataItem, "FIsEnroll").ToString())
                                    {
                                        case "Y":
                                            {
                                                ViewContext.Writer.Write("录用");
                                                break;
                                            }
                                        case "N":
                                            {
                                                ViewContext.Writer.Write("未录用");
                                                break;
                                            }
                                        case "U":
                                            {
                                                ViewContext.Writer.Write("修改");
                                                break;
                                            }
                                    }
                                }

                            });
                            column.CellStyle.Wrap = DefaultBoolean.False;
                        });


                        settings.SettingsBehavior.AllowSort = false;
                        settings.SettingsBehavior.AllowDragDrop = false;
                        settings.SettingsBehavior.AllowSelectByRowClick = false;
                        settings.SettingsLoadingPanel.Text = "数据读取中...";
                        settings.SettingsBehavior.AllowClientEventsOnLoad = false;
                        settings.SettingsBehavior.AllowFocusedRow = true;


                        settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";

                        settings.CommandColumn.Visible = true;
                        settings.CommandColumn.ShowSelectCheckbox = true;
                        settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Pixel(5);

                        settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
                        settings.SettingsPager.FirstPageButton.Visible = true;
                        settings.SettingsPager.LastPageButton.Visible = true;
                        settings.SettingsPager.PageSize = ElingOA6_Admin_DSJCJ.Common.GlobalConstant.CONSTRING_PAGESIZE;
                        settings.SettingsPager.AlwaysShowPager = true;

                        settings.CommandColumn.SetHeaderTemplateContent(c =>
                        {
                            Html.DevExpress().CheckBox(settingsCheckBox =>
                            {
                                settingsCheckBox.Name = "cbSelectAll";
                                settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectAllRowsOnPage(); else {0}.UnselectAllRowsOnPage(); }}", settings.Name);

                                if (c.Grid.VisibleRowCount == 0)
                                {
                                    settingsCheckBox.Enabled = false;

                                }
                                else
                                {
                                    settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
                                }


                            }).Render();
                        });


                        settings.PageIndexChanged = (sender, e) =>
                        {
                            ASPxGridView grid = (ASPxGridView)sender;
                            grid.Selection.UnselectAll();
                        };
                        settings.DataBound = (sender, e) =>
                        {
                            ASPxGridView grid = (ASPxGridView)sender;
                            if (ViewData["pageIndex"] != null && ViewData["pageIndex"].ToString() != "")
                            {
                                if (grid.PageCount < int.Parse(ViewData["pageIndex"].ToString()))
                                {
                                    grid.PageIndex = 0;
                                }
                                else
                                {
                                    grid.PageIndex = int.Parse(ViewData["pageIndex"].ToString());
                                }
                            }
                        };
                        settings.DataBinding = (sender, e) =>
                        {
                            ASPxGridView grid = (ASPxGridView)sender;
                            for (int i = 0; i < grid.AllColumns.Count; i++)
                            {
                                if (grid.AllColumns[i].CellStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                                {
                                    grid.AllColumns[i].CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                                }
                                if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                                {
                                    grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                                }
                            }


                        };

            }).Bind(Model.DocumentList).GetHtml()
